<%@ page import="pojo.Student" %>
<%@ page import="java.util.List" %>
<%--
  Created by IntelliJ IDEA.
  User: 33503
  Date: 2023/11/30
  Time: 11:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>课程详情</title>
  <!--引入jquery和bootstrap -->
  <script type="text/javascript" src="js/jquery-1.12.3.min.js"></script>
  <script type="text/javascript" src="js/bootstrap.min.js"></script>
  <style>
    table{
      width: 93.8%;
    }
    th{
      border: 1px solid #000000;
      text-align: center;
      padding: 15px 0;
      background-color: #66afe9;
      height: 40px;
      font-size: 22px;
      color: white;
    }
    td{
      border: 1px solid #000000;
      text-align: center;
      padding: 15px 0;
      height: 40px;
    }
    table tbody tr:hover{
      background-color: #a6e1ec;
    }
    #mytable th{
      text-align: center;
    }
    .content_input .my-input{/*搜索框样式*/
      margin-top: 20px;
      width: 66%;
      height: 38px;
      border-radius: 5px;
      color: black;
      border: 1px solid #3388FF;
    }
    .content_input .search_btn{ /*按钮样式*/
      width: 80px;
      height: 40px;
      background-color:dodgerblue;
    }
    .content_input .search_btn:hover{ /*按钮覆盖样式*/
      background-color: #2e6da4;
      color: ivory;
    }
    .button-delete-stu{/*删除学生按钮样式*/
      width: 90px;
      height: 30px;
      text-align: center;
      background-color: #df5000;
      border-color: #a6e1ec;
      color: white;
      font-size: medium;
    }
  </style>
</head>
<body>
<%--菜单栏--%>
<jsp:include page="teacher_menu.jsp"></jsp:include>
<div style="background-color: #66afe9;display: inline-block;margin-top: 10px;float: left;margin-left: 20%;height: 80px;width: 200px;text-align: center; border-radius:0px;">
  <h1 style="color:white;text-shadow: 2px 2px 2px dodgerblue;line-height: 40px;border-radius:2px;font-size: 25px">学生名单</h1>
</div>
<div style="margin-left: 35%;margin-top:10px;width: 60%;height:80px;background-color: #66afe9; display: flex;">
  <form style="padding-left: 10%" action="${pageContext.request.contextPath }/findDetailStudentByStudentId" method="POST" id="xhcz">
    <div class="content_input">
      <input class="my-input" type="text" name="s_id" id="s_id" placeholder="请输入学生学号" aria-label="Search">
      <input class="btn btn-primary search_btn" type="button" value="查询" onclick="cz()">
    </div>
  </form>
  <%--所有--%>
  <div class="content_input" style="margin-top: 20px; margin-left: 10px">
    <form style="padding-left: 10%" action="${pageContext.request.contextPath }/CourseListDetail" method="POST">
      <input type="submit" value="所有" class="btn btn-primary search_btn">
    </form>
  </div>
</div>
<div style="margin-left: 20%; margin-top: 20px">
  <a href="${pageContext.request.contextPath}/courseList" style="display: inline-block; background-color: #66afe9; font-size: 15px; float: left;color: black;margin-bottom: 10px"><strong><</strong>返回上一级</a>
  <table id="mytable">
    <thead>
    <tr>
      <th>学号</th>
      <th>学生姓名</th>
      <th>班级</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <!--  展示选课学生信息-->
    <%
      List<Student> students=(List<Student>)session.getAttribute("get_detailStudents");
      if(students==null||students.isEmpty()){
    %>
    <tr>
      <td colspan="4" style="text-align: center">数据为空</td>
    </tr>
    <%
    }else{
      for(Student s:students){
    %>
    <tr>
      <td><%=s.getS_id()%></td>
      <td><%=s.getS_name()%></td>
      <td><%=s.getS_class()%></td>
      <td>
        <input class="button-delete-stu" type="button" value="删除">
      </td>
    </tr>
    <%
        }}
    %>
    </tbody>
  </table>
</div>
</body>
</html>
<script>
  //查找时不输入查询学号则显示您输入的学号为空
  function myTrim(x) {
    return x.replace(/^\s+|\s+$/gm, '');
  }
  function cz() {
    //提交form表单前判断
    var s_id = myTrim($("#s_id").val());//消除空格
    if (s_id === "" || s_id == null) {
      alert("您输入的学号为空！");
      return;
    } else {
      //试题类型为单选题或多选题时，CD选项不可为空
      $("#xhcz").submit();
      return false;
    }
  }
  //删除学生
  $(function() {
    $(".button-delete-stu").click(function() {
      var s_id=$(this).parents("tr").children("td:nth-child(1)").text();//获取点击删除对应的教师
      $.ajax({//传数据给controller进行删除
        type: "post",
        url: "${pageContext.request.contextPath }/deleteCourseStudent",
        data: {
          "s_id": s_id
        },
        success: function (data) {
          console.log(data);
          if(data==true) {//删除成功
            alert("删除成功！")
            window.location.replace("${pageContext.request.contextPath }/CourseListDetail");
          }else {
            alert("删除失败！")
          }
        }
      });
    })
  })
</script>